//百度地图调用API
var bmap = new BMap.Map("bdmap");    // 创建Map实例
window.bdmap1={
		/**
		 *time    ：2018/5/29
		 *author  ：唐仁松
		 *describe：地图渲染
		 *
		 *参数说明：x，y为坐标值
		 *max：为显示地图层级
		 *
		 */
		into:function(x,y,max){
			bmap.centerAndZoom(new BMap.Point(x,y), max);  // 初始化地图,设置中心点坐标和地图级别
			//添加地图类型控件
			bmap.addControl(new BMap.MapTypeControl({
				mapTypes:[
		            BMAP_NORMAL_MAP
		            //BMAP_HYBRID_MAP
		        ]}));
		    var initPoint1 = new BMap.Point(pointx, pointy);
			bmap.setCurrentCity(initPoint1,12);  // 设置地图显示的城市 此项是必须设置的
			bmap.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
		},
		/**
		 *time    ：2018/5/29
		 *author  ：唐仁松
		 *describe：地图添加行政区域
		 *
		 *参数说明：palce为区域名字
		 *color:为线条颜色
		 *
		 */
		 getBoundary:function(data,color){
			 var bdary = new BMap.Boundary();
			var aaa020=$('.palce_x ul li.active').attr('id');
			var pointArray = [];
			$.ajax({
					url: "getMapData",
					data: {
						aaa020:data==null?aaa020:data,
						type:1
					},
					success: function(data) {
						$.each(data.data, function(i, val) {
							var ab=eval("zjmap."+this.abbrbc)
							var ply = new BMap.Polygon(ab, {strokeWeight: 1, strokeColor: this.color,fillOpacity:0.12,fillColor:this.color}); //建立多边形覆盖物
							bmap.addOverlay(ply);
							pointArray = pointArray.concat(ply.getPath());
						})
					}
			});
		},
		/**
		 *time    ：2018/5/29
		 *author  ：唐仁松
		 *describe：更新视图
		 *
		 *参数说明：data为区域名字
		 *color:为线条颜色
		 *
		 */
		view:function(data){
			 var bdary = new BMap.Boundary();
			var aaa020=$('.palce_x ul li.active').attr('id');
			var pointArray = [];
			$.ajax({
					url: "getMapData",
					data: {
						aaa020:aaa020,
						type:1
					},
					success: function(data) {
						$.each(data.data, function(i, val) {
							var ab=eval("zjmap."+this.abbrbc)
							var ply = new BMap.Polygon(ab, {strokeWeight: 1, strokeColor: this.color,fillOpacity:0.12,fillColor:this.color}); //建立多边形覆盖物
							bmap.addOverlay(ply);
							pointArray = pointArray.concat(ply.getPath());
						})
						bmap.setViewport(pointArray,12);
						if(aaa020==3301){
							bdmap.into(120.1,30.86,11);
						}
					}
			});
		},
		/**
		 *time    ：2018/5/30
		 *author  ：唐仁松
		 *describe：初始渲染区域数组
		 *
		 *参数说明：palce为区域名字
		 *color:为线条颜色
		 *
		 */
		madeBoundary:function(orgAaa020){
			var datas = new Array('湖州市-#66559','湖州市南浔区-#666ddd','湖州市开发区-#666ddd','湖州市德清县-#1199cc','湖州市长兴县-#e4393c','湖州市安吉县-#ddd','湖州市吴兴区-#eee');
	        var bdary = new BMap.Boundary();
	        	bdmap.getBoundary(orgAaa020,'#e4393c');
		},
		/**
		 *time    ：2018/5/30
		 *author  ：唐仁松
		 *describe：创建覆盖物
		 *
		 *参数说明：palce为区域名字
		 *color:为线条颜色
		 *
		 */
		add:function(point, text, mouseoverText){
			this._point = point;
		    this._text = text;
		    this._overText = mouseoverText;
		},
		/**
		*time    ：2018/5/30
		*author  ：唐仁松
		*describe：实时数据点动态
		*
		*参数说明：palce为区域名字
		*color:为线条颜色
		*
		*/
		movedi:function(id,num){
			var div=$('.trs'+id);
			var txt=parseInt(div.find('span').text());
			if(txt!=num){
				div.find('span').html(num);
				div.addClass('active');
				window.setTimeout(function(){
					div.removeClass('active')
				},2000)
			}
		}

}
//覆盖物继承链
var timer1;
bdmap1.add.prototype = new BMap.Overlay();
bdmap1.add.prototype.initialize = function(map){
	this._map = map;
	var div = this._div = document.createElement("div");
    div.style.position = "absolute";
    div.className ='trs'+this._overText;
	div.className +=' '+'bzd';
	if(this._overText==330503||this._overText==330521||this._overText==330522||this._overText==330523||this._overText==330502){
		div.style.cursor = "pointer";
	}
	div.setAttribute("datai",this._overText);
    div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
    div.style.color = "white";
    div.style.height = "60px";
    div.style.width = "40px";
    div.style.lineHeight = "18px";
    div.style.whiteSpace = "nowrap";
    div.style.MozUserSelect = "none";
    div.style.fontSize = "12px"
    var span = this._span = document.createElement("span");
    span.style.position = "absolute";
    span.style.height = "40px";
    span.style.top = "0px";
    span.style.left = "0px";
    span.style.right = "0px";
    span.style.bottom = "0px";
    span.style.margin = "auto";
    span.style.textAlign ='center';
    span.style.overflow = "hidden";
    div.appendChild(span);
    span.appendChild(document.createTextNode(this._text));
    var that = this;
    var arrow = this._arrow = document.createElement("div");
    div.appendChild(arrow);
	div.onmouseover = function(){
		var id1=$(this).attr('datai');
		var x=$(this).offset().left-30;
		var y=$(this).offset().top-50;
		var post;
		clearInterval(timer1);
		var txt = $(".palce_x ul li.active").text();
		if("湖州市"==txt){
			post={aaa020:id1}
		}else{
			post={aaa020:id1,type:1}
		}
		// tool.ajax('../../analy/monitor/getJwdDetailData',post,function(data){
		// 	window.map.modal(data.data,x,y);
		// });
    }
//    div.onmouseout = function(){
//			timer1=setTimeout(function(){
//				$('#modal1').hide();
//     },5000);
//    }
			div.onclick = function(){
				var id1=$(this).attr('datai');
				$('#'+id1).click();
			}
    bmap.getPanes().labelPane.appendChild(div);
    return div;
}
bdmap1.add.prototype.draw = function(){
	 var mp = this._map;
     var pixel = mp.pointToOverlayPixel(this._point);
     console.log(pixel)
     this._div.style.left = pixel.x-20+ "px";
     this._div.style.top  = pixel.y-30+ "px";
}
